package com.shady.diskmanger.dao;

import com.shady.diskmanger.model.BigFile;
import com.shady.diskmanger.model.TransferLog;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class CreateThreadDao {
    private static final int THREAD_NUM = 15;

    public boolean createbigFileCopyThread(File src, File dest) {
        if (!src.exists() || src.length() <= 0) {
            System.out.println("您输入的源文件地址有误请重试");
            return false;
        }
        if (!dest.exists() || !dest.isDirectory()) {
            System.out.println("您输入的目标地址有误请重试");
            return false;
        }
        long fileSize = src.length();
        long transferSize = fileSize / THREAD_NUM + 1;
        // 使用循环来一次性创建多个线程并启动
        for (int i = 0; i < THREAD_NUM; i++) {
            BigFile bigFile = new BigFile(i * transferSize, transferSize, src, dest);
            bigFile.setDest(bigFile.getDest());
            FilesFunctionDao filesFunctionDao = new FilesFunctionDao();
            Runnable runnable = () -> filesFunctionDao.bigFileCopy(bigFile);
            new Thread(runnable).start();
        }
        return true;
    }

}